from PySide6.QtCore import QDir, Qt
from PySide6.QtGui import QStandardItemModel, QStandardItem
from PySide6.QtWidgets import QApplication, QTreeView, QVBoxLayout, QWidget,QFileSystemModel

class MainWindow(QWidget):
    def __init__(self):
        super().__init__()

        self.treeView = QTreeView()
        self.model = QStandardItemModel()
        self.treeView.setModel(self.model)

        layout = QVBoxLayout()
        layout.addWidget(self.treeView)
        self.setLayout(layout)

        self.treeView.clicked.connect(self.onTreeViewClicked)

        self.fileSystemModel = QFileSystemModel()
        self.fileSystemModel.setRootPath('D:\\a_开发测试文档\\02_ExampleCode')
        self.treeView.setRootIndex(self.fileSystemModel.index('D:\\a_开发测试文档\\02_ExampleCode'))

    def onTreeViewClicked(self, index):
        if index.isValid():
            filePath = self.fileSystemModel.filePath(index)
            if QDir(filePath).isDir():
                self.treeView.setRootIndex(index)

app = QApplication([])
window = MainWindow()
window.show()
app.exec()